﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KATS_Client
{
    /// <summary>
    /// The KATS Client class
    /// </summary>
    class Program
    {
        /// <summary>
        /// Program is exiting
        /// </summary>
        public static event EventHandler<EventArgs> Exiting;

        /// <summary>
        /// Start the client
        /// </summary>
        /// <param name="args">Runtime arguments</param>
        [STAThread]
        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.Name = "Main Thread";
            Server.Server.Start_Threaded();
            Client.ServerConnection.MakeNewMainConnection_Threaded();

            //byte[] data = new byte[1024*16];
            //Random r = new Random();
            //r.NextBytes(data);
            //while (true)
            //{
            //    DateTime start = DateTime.Now;
                
            //    for (int i = 0; i < 200; i++)
            //    {
            //        Client.ServerConnection.Server.SendFileChunk(data); 
            //    }
            //    Console.WriteLine("Time Taken: " + (DateTime.Now - start).TotalMilliseconds + " ms");
            //}

            //return;


            Client.FileActionsQueue.Initialize_Threaded();
            UI.WindowManager.Initialise();
            UI.WindowManager.Refresh_AllTabs_Threaded(false);

            UI.MainWindow mw = new UI.MainWindow();
            System.Windows.Forms.Application.Run(mw);

            Console.WriteLine("Exiting...");
        }

        /// <summary>
        /// Exit the program
        /// </summary>
        public static void Exit()
        {
            // program is closing
            // so ensure that everything that needs to be saved is saved
            if (Exiting != null)
                Exiting(new object(), new EventArgs());
            System.Windows.Forms.Application.Exit();

            Environment.Exit(0);
        }
    }
}
